package com.badibadi.fragment;

import com.badibadi.mytools.TabHostUtils;
import com.badibadi.uniclubber.R;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TabHost;
//这个不管
public class WaterFallFragment_1_main extends BaseFragment {
	private WaterFallFragment_1 fragment0;
	//改
	private ShouYeHuoDongFragment fragment1;
	private ShouYeJuLeBuFragment fragment2;
	private FragmentManager manager;
	private Bundle bun = null;
	private TabHost mTabHost;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(R.layout.waterfall_main_after, null);
		manager = getActivity().getSupportFragmentManager();
		initTabHost(view);
		LoadFragment(0);
		return view;
	}

	private void initTabHost(View v) {
		// TODO Auto-generated method stub
		mTabHost = (TabHost) v.findViewById(R.id.before_landing_tabhost);
		mTabHost.setup();
		mTabHost.addTab(mTabHost
				.newTabSpec("before_landing_tabhost one")
				.setIndicator(getResources().getString(R.string.newest_moment),
						getResources().getDrawable(R.drawable.ic_launcher))
				.setContent(R.id.tab1));
		mTabHost.addTab(mTabHost
				.newTabSpec("before_landing_tabhost two")
				.setIndicator(getResources().getString(R.string.wx_activity),
						getResources().getDrawable(R.drawable.ic_launcher))
				.setContent(R.id.tab2));
		mTabHost.addTab(mTabHost
				.newTabSpec("before_landing_tabhost three")
				.setIndicator(getResources().getString(R.string.wx_club),
						getResources().getDrawable(R.drawable.ic_launcher))
				.setContent(R.id.tab3));
		TabHostUtils.SetTabHost(getActivity(), mTabHost);
		mTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {

			@Override
			public void onTabChanged(String tabId) {
				// TODO Auto-generated method stub
				// Toast.makeText(getApplicationContext(),
				// "" + mTabHost.getCurrentTab(), 0).show();
				switch (mTabHost.getCurrentTab()) {
				case 0:
					LoadFragment(0);
					break;
				case 1:
					LoadFragment(1);
					break;
				case 2:
					LoadFragment(2);
					break;
				}
			}
		});
	}

	protected void LoadFragment(int num) {
		bun = new Bundle();
		switch (num) {
		case 0:
			FragmentTransaction transaction = manager.beginTransaction();
			fragment0 = WaterFallFragment_1.getInstance();
			bun.putInt("type", 3);
			fragment0.setArguments(bun);
			transaction.replace(R.id.before_landing_right_layout, fragment0);
			transaction.commit();
			break;
		case 1:
			FragmentTransaction transaction2 = manager.beginTransaction();
			fragment1 = new ShouYeHuoDongFragment();
			bun.putString("uid", "1");
			bun.putInt("type", 0);
			fragment1.setArguments(bun);
			transaction2.replace(R.id.before_landing_right_layout, fragment1);
			transaction2.commit();
			break;
		case 2:
			FragmentTransaction transaction3 = manager.beginTransaction();
			fragment2 = new ShouYeJuLeBuFragment();
			bun.putString("type", "0");
			fragment2.setArguments(bun);
			transaction3.replace(R.id.before_landing_right_layout, fragment2);
			transaction3.commit();
			break;
		}
	}
	class ShuaXinJiekou implements Shuaxin{

		@Override
		public void Resh() {
			// TODO Auto-generated method stub
			LoadFragment(0);
		}
		
	}
	
	
	public void setOnRefresh()
	{
		new ShuaXinJiekou().Resh();
	}
	
	public interface Shuaxin{
		void Resh();
	}
	
}

